package com.ysq.www.api.user.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ysq.www.api.user.entity.Comment;
import com.ysq.www.api.user.service.ICommentService;
import com.ysq.www.common.annotation.AuthToken;
import com.ysq.www.common.result.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author dql
 * @since 2020-08-18
 */
@RestController
@RequestMapping("/user/comment")
public class CommentController {

    @Autowired
    private ICommentService commentService;


    /**
     * 分页查询评论
     * @param type 评论类型：1资讯
     * @param cId 内容id
     * @param pageNumber 页码
     * @param pageSize 页大小
     * @return ResultMsg
     */
    @GetMapping("/list")
    @AuthToken
    public ResultMsg selectListById(Integer type,Integer cId,Integer pageNumber,Integer pageSize){
        IPage<Comment> cPage = commentService.selectListById(type,cId,pageNumber,pageSize);
        return ResultMsg.SUCCESS.setNewMsg("查询成功").setNewData(cPage);
    }

    /**
     * 新增评论
     * @param comment 评论对象
     * @return ResultMsg
     */
    @PostMapping("/add")
    @AuthToken
    public ResultMsg addComment(@RequestBody Comment comment){
        ResultMsg rm = commentService.addComment(comment);
        return rm;
    }



}
